
import {getshippingaddressApi} from "@/api/myinter.js"
import {goodsDetailsApi} from"@/api/goods.js"
export default {
    namespaced:'address',
    state:{
       dev:[],
	   price:0,
	   list:[],
	   detail:'',
	   name:'',
	   companyName:'',
	   brandName:'',
	   stock:0,
	   couponsStartQuantity:0,
	   moneyStartQuantity:0,
	   detail:'',
	   newDev:[],
    },
	mutations:{
	    changeAddress(state, item){
			 state.dev = item;
		},
		changeGoods(state, item){
			state.price = item.price
			state.list = item.imgUrlList
			state.name = item.name
			state.brandName = item.brandName
			state.companyName = item.companyName
			state.stock = item.stock
			state.moneyStartQuantity = item.moneyStartQuantity
			state.couponsStartQuantity = item.couponsStartQuantity
			state.detail = item.detail
		},
		filterTrue(state){
			state.newDev  = state.dev.filter(item=>item.default===true)
		},
		filterData(state, val){
			state.newDev  = state.dev.filter(item=>item.id===val)
		}
	},
    actions:{
        async getAddressData(context) {
        	uni.showLoading({
        		title: "正在加载中...."
        	})
        	const res = await getshippingaddressApi({})
        	if (res.statusCode === 200) {
        		uni.hideLoading()
        		context.commit('changeAddress', res.data.data);
        	}
        },
		async getGoodsData(context,id){
			uni.showLoading({
				title:"正在加载中...."
			})
			const res = await goodsDetailsApi(id)
			if(res.statusCode===200){
				uni.hideLoading()
				context.commit('changeGoods', res.data.data);
			}
		},
    }
}